#include "PerceptSeq.hpp"
#include <sstream>

PerceptSeq::PerceptSeq()
{
	// initialisations des données
	DataManager*	perceptSeq = new DataManager("Percept");
	this -> _perceptManager = perceptSeq;
	// percepts
	perceptSeq->getType(perceptSeq -> addType("nourriture"))->addValues("Yes", "No", 0);
	perceptSeq->getType(perceptSeq -> addType("ennemi"))->addValues("Yes", "No", 0);
	perceptSeq->getType(perceptSeq -> addType("faim"))->addValues("Mourrant", "Affamé", "Normal", "Repu", 0);
	perceptSeq->getType(perceptSeq -> addType("nuit"))->addValues("Yes", "No", 0);
}

void		PerceptSeq::initTest()
{
	std::list<Data*>*	seq = new std::list<Data*>();
	
	seq -> push_back( new Data(0, 0) );
	seq -> push_back( new Data(1, 0) );
	seq -> push_back( new Data(2, 3) );
	seq -> push_back( new Data(3, 0) );
	
	this -> _dataSets.insert(std::pair<unsigned int, std::list<Data*> >(0, *seq));
}

std::string	PerceptSeq::getOutputSeq(unsigned int id) const
{
	std::ostringstream	ret("");
	std::map<unsigned int, std::list<Data*> >::const_iterator	check = this -> _dataSets.find(id);
	DataType*		type = NULL;
	
	ret << "Percept sequence : ";
	if (check == this -> _dataSets.end())
		ret << "not found for id " << id;
	else
	{
		std::list<Data*>			seq = check -> second;
		std::list<Data*>::iterator		it = seq . begin();
		std::list<Data*>::iterator		ite = seq . end();
		
		for (; it != ite; ++it)
		{
			type = this -> _perceptManager -> getType((*it) -> getType());
			ret << type -> getName() << "=" << type -> getValueName((*it) -> getValue()) << ",\t";
		}
	}
	return ret.str();
}

void		PerceptSeq::genEntropies()
{
	this -> getEntropies(this -> _perceptManager);
}

std::string	PerceptSeq::displayEntropies() const
{
	std::ostringstream				ret("");
	std::map<unsigned int, double>::const_iterator	it = this -> _entropies.begin();
	std::map<unsigned int, double>::const_iterator	ite = this -> _entropies.end();

	for (; it != ite; ++it)
	{
		ret << "E(" << (this -> _perceptManager -> getType(it -> first)) -> getName() << ") = " << it -> second << std::endl;
	}
	return ret.str();
}

